import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 0
 * Date: 2023-03-12
 * Time: 17:34
 */
public class Test {

    public static void main7(String[] args) {
        int[][] array1 = {{1,2,3},{4,5,6}};
        System.out.println(array1.length);//行的长度
        System.out.println(array1[1].length);//每一列的长度

        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j <  array1[i].length; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println("=================");
        for(int[] tmp : array1) {
            for(int x : tmp) {
                System.out.print(x+" ");
            }
            System.out.println();
        }
        System.out.println("=============");
        String ret = Arrays.deepToString(array1);
        System.out.println(ret);
    }

    public static void main8(String[] args) {
        int[] array = new int[]{1,2,3};
        /*for (int i = 0; i < array.length; i++) {
            array[i] = i+1;
        }
        System.out.println(Arrays.toString(array));*/

        //Arrays.fill(array,0,3,8);//[0,3)
        func3(array);
        System.out.println(Arrays.toString(array));
    }

    public static void func3(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array[i]*2;
        }
    }
    public static void main(String[] args) {
        int[][] array1 = new int[2][];//Java当中 不可以省略行  但是可以省略开列

        array1[0] = new int[3];
        array1[1] = new int[5];

        System.out.println(array1.length);//行的长度
        System.out.println(array1[1].length);//每一列的长度

        for (int i = 0; i < array1.length; i++) {
            for (int j = 0; j <  array1[i].length; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
    }

    public static void main5(String[] args) {
        int[][] array1 = {{1,2,3},{4,5,6}};
        int[][] array2 = new int[2][3];
        int[][] array3 = new int[][]{{1,2,3},{4,5,6}};

        for (int i = 0; i < 2; i++) {
            for (int j = 0; j < 3; j++) {
                System.out.print(array1[i][j]+" ");
            }
            System.out.println();
        }
    }

    /*public static void main3(String[] args) {
        int[] array = {1,2,3,4,5,6};
        adjust(array);
    }*/

    /*public  static int[] adjust(int[] array){
        int left = 0;
        int right = array.length-1;
        for (int i = 0; i < array.length; i++) {
            if((i+1)%2 == 0) {
                int tmp = array[i+1];
                array[i+1] = array[];
            }
        }
    }*/
    public static void main2(String[] args) {
        //int[] array = {1,2,3,4,5};
        /*int key = 5;
        //int index = binarySearch(array,key);
        int index = Arrays.binarySearch(array,5);
        System.out.println(index);*/
        /*int[] array = {2,3,7,95,94,10,1,100};
        //bubbleSort(array);
        Arrays.sort(array);
        System.out.println(Arrays.toString(array));*/
        int[] array = {1,2,3,4,5};
        /*int[] copy = new int[array.length];
        System.arraycopy(array,0,copy,0,array.length);
        System.out.println(Arrays.toString(copy));*/
        /*int[] ret = Arrays.copyOfRange(array,1,3);//[1,3)
        System.out.println(Arrays.toString(ret));*/
        /*int[] ret = copy(array);
        System.out.println(Arrays.toString(ret));
        System.out.println("===========");
        int[] ret2 =Arrays.copyOf(array,array.length*2);
        System.out.println(Arrays.toString(ret2));*/
        reverseArray(array);
        System.out.println(Arrays.toString(array));

    }
    public static void reverseArray(int[] array) {
        int i = 0;
        int j = array.length-1;
        while (i < j) {
            int tmp = array[i];
            array[i] = array[j];
            array[j] = tmp;
            i++;
            j--;
        }
    }


    public static int[] copy(int[] array) {
        int[] copyArray = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            copyArray[i] = array[i];
        }
        return copyArray;
    }


    public static void bubbleSort(int[] array) {
        for(int i = 0; i < array.length-1; i++) {
            boolean flag = false;
            for(int j = 0; j < array.length-1-i; j++) {
                if(array[j]>array[j+1]) {
                    int tmp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = tmp;
                    flag = true;
                }
            }
            if(flag == false) {
                break;
            }
        }
    }

    public static int binarySearch(int[] array,int key) {
        int left = 0;
        int right = array.length-1;
        while(left<=right) {
            int mid = (right+left)/2;
            if(array[mid]>key) {
                right = mid - 1;
            }else if(array[mid]<key) {
                left = mid + 1;
            }else {
                return mid;
            }
        }
        return -1;
    }
}


